package com.project.controller;

import com.project.bean.UserClass1Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;

/**
 * @author lyl
 * description:应用控制器
 */
@Controller //标识为Spring组件
public class TestController {
    /**
     * 客户端以/mytest进行请求,需要与表单中的action一致
     * 就以此方法进行处理
     *
     * @return
     */
    @RequestMapping("/mytest")
    public String test() {
        System.out.println("测试方法");
        //进行页面跳转，设置转换路径
        return "redirect:/html/index.html";
    }

    /**
     * 按照表单名和属性名相同的原则，将表单数据封装为实体对象
     * 当表单名与属性名不一致时可以以@RequestParam注解的形式进行说明
     *
     * @param userBean
     * @param checkCode
     * @param userMoney
     * @param response
     * @throws IOException
     */
    @RequestMapping("add")
    public void add(UserClass1Bean userBean, String checkCode, @RequestParam("money") int userMoney, LocalDate birthday, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        System.out.println(userBean);
        response.getWriter().println(userBean + "   " + checkCode + "   " + userMoney);
        response.getWriter().println("<hr>");
        response.getWriter().println("生日" + birthday);
    }

}
